package com.lahuan;

import com.alibaba.csp.sentinel.init.InitExecutor;
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.Collections;

/**
 * @author linfy
 */
@EnableDubbo
@EnableSwagger2
@SpringBootApplication
public class AccountRmbSpringBootApplication {

    public static void main(String[] args) {
        InitExecutor.doInit();
        initFlowRule();
        SpringApplication.run(AccountRmbSpringBootApplication.class, args);
    }

    private static void initFlowRule() {
        FlowRule flowRule = new FlowRule();
        //针对具体的资源限流
        //com.lahuan.impl.AccountRmbServiceImpl
        flowRule.setResource("com.lahuan.demo.service.AccountRmbService:froze(java.lang.Long,java.math.BigDecimal,java.lang.String)");
        //flowRule.setResource("com.lahuan.controller.TestController");
        flowRule.setCount(10);
        flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS);
        flowRule.setLimitApp("default");
        flowRule.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_DEFAULT);
        FlowRuleManager.loadRules(Collections.singletonList(flowRule));
    }
}
